package com.lc.qianrenshiye.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/12/5.
 */
@HttpInlet(Conn.GAINS_SUBSIDIES)
public class AllowancePost extends BaseAsyPost<AllowancePost.AllowanceListEntity> {

    public String sid, pay, time, type, start, end;

    public AllowancePost(AsyCallBack<AllowanceListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected AllowanceListEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            AllowanceListEntity allowanceListEntity = new AllowanceListEntity();

            allowanceListEntity.knot = object.optString("knot");
            allowanceListEntity.nkont = object.optString("nkont");
            allowanceListEntity.total = object.optString("total");

            JSONArray array = object.optJSONArray("list");

            if (array != null) {

                for (int i = 0; i < array.length(); i++) {

                    JSONObject entityObject = array.optJSONObject(i);

                    AllowanceEntity allowanceEntity = new AllowanceEntity();

                    allowanceEntity.id = entityObject.optString("id");
                    allowanceEntity.ordersn = entityObject.optString("ordersn");
                    allowanceEntity.posttime = entityObject.optString("posttime");
                    allowanceEntity.subsidies = entityObject.optString("subsidies");
                    allowanceEntity.sub_state = entityObject.optString("sub_state");
                    allowanceEntity.sub_time = entityObject.optString("sub_time");
                    allowanceEntity.sub_money = entityObject.optString("sub_money");

                    allowanceListEntity.allowanceEntityList.add(allowanceEntity);

                }
            }

            return allowanceListEntity;

        }

        return null;

    }

    public static class AllowanceListEntity {

        public String total, knot, nkont;

        public List<AllowanceEntity> allowanceEntityList = new ArrayList<>();

    }

    public static class AllowanceEntity {

        public String id, ordersn, posttime, subsidies, sub_state, sub_time, sub_money;

    }

}
